home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / dtype / fontdt1.0.lha / Src / classbase.c next >
C/C++ Source or Header  |  1995-04-22  |  4KB  |  122 lines

  1. /*
  2. **    classbase.c - implementation of standard function for Font DataType class
  3. **    Copyright © 1995 Michael Letowski
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/libraries.h>
  8. #include <exec/semaphores.h>
  9. #include <dos/dos.h>
  10. #include <support/types.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14.  
  15. #include "classbase.h"
  16. #include "dispatch.h"
  17.  
  18. #define INT_NAME        "intuition.library"
  19. #define INT_VERN        39
  20. #define GFX_NAME        "graphics.library"
  21. #define GFX_VERN        39
  22. #define DOS_NAME        "dos.library"
  23. #define DOS_VERN        39
  24. #define UTIL_NAME        "utility.library"
  25. #define UTIL_VERN        39
  26. #define DT_NAME            "datatypes.library"
  27. #define DT_VERN            39
  28. #define DF_NAME            "diskfont.library"
  29. #define DF_VERN            39
  30. #define PDT_NAME        "datatypes/picture.datatype"
  31. #define PDT_VERN        39
  32.  
  33. ASM Class *ObtainFontEngine(R_A6 struct ClassBase *cb)
  34. {
  35.     return(cb->cb_Class);
  36. }    /* ObtainREKOEngine */
  37.  
  38. ASM struct ClassBase *LibInit(R_D0 struct ClassBase *cb, R_A0 BPTR segList,
  39.                                                             R_A6 struct Library *sysBase)
  40. {
  41.     cb->cb_SegList=segList;
  42.     cb->cb_SysBase=sysBase;
  43.     InitSemaphore(&cb->cb_Lock);                                    /* Initialize locking */
  44.     try(cb->cb_IntuitionBase=OpenLibrary(INT_NAME,INT_VERN),    NO_INT);
  45.     try(cb->cb_GfxBase=OpenLibrary(GFX_NAME,GFX_VERN),                NO_GFX);
  46.     try(cb->cb_DOSBase=OpenLibrary(DOS_NAME,DOS_VERN),                NO_DOS);
  47.     try(cb->cb_UtilityBase=OpenLibrary(UTIL_NAME,UTIL_VERN),    NO_UTIL);
  48.     return(cb);
  49.  
  50.     except(NO_UTIL,    CloseLibrary(cb->cb_UtilityBase));
  51.     except(NO_DOS,    CloseLibrary(cb->cb_DOSBase));
  52.     except(NO_GFX,    CloseLibrary(cb->cb_GfxBase));
  53.     except(NO_INT,    CloseLibrary(cb->cb_IntuitionBase));
  54.     return(NULL);
  55. }    /* LibInit */
  56.  
  57. ASM struct ClassBase *LibOpen(R_A6 struct ClassBase *cb)
  58. {
  59.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  60.     fclr(cb->cb_Lib.lib_Flags,LIBF_DELEXP);                /* No delayed expunge */
  61.  
  62.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class==NULL)
  63.     {                                                                                            /* First open */
  64.         try(cb->cb_DataTypesBase=OpenLibrary(DT_NAME,DT_VERN),        NO_DT);
  65.         try(cb->cb_DiskfontBase=OpenLibrary(DF_NAME,DF_VERN),            NO_DF);
  66.         try(cb->cb_SuperClassBase=OpenLibrary(PDT_NAME,PDT_VERN),    NO_PDT);
  67.         try(cb->cb_Class=InitClass(cb),                                                        NO_CLASS);
  68.     }
  69.  
  70.     cb->cb_Lib.lib_OpenCnt++;                                            /* Mark successfull opening */
  71.     ReleaseSemaphore(&cb->cb_Lock);                                /* Data modified */
  72.     return(cb);                                                                        /* Return success */
  73.  
  74.     except(NO_CLASS,FreeClass(cb->cb_Class));
  75.     except(NO_PDT,    CloseLibrary(cb->cb_SuperClassBase));
  76.     except(NO_DF,        CloseLibrary(cb->cb_DiskfontBase));
  77.     except(NO_DT,        CloseLibrary(cb->cb_DataTypesBase));
  78.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  79.     return(NULL);                                                                    /* Return failure */
  80. }    /* LibOpen */
  81.  
  82. ASM BPTR LibClose(R_A6 struct ClassBase *cb)
  83. {
  84.     BPTR Seg=0;
  85.  
  86.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  87.     if(cb->cb_Lib.lib_OpenCnt)
  88.         cb->cb_Lib.lib_OpenCnt--;                                        /* Decrease open count */
  89.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class)
  90.         if(FreeClass(cb->cb_Class))
  91.         {
  92.             cb->cb_Class=NULL;
  93.             CloseLibrary(cb->cb_SuperClassBase);
  94.             CloseLibrary(cb->cb_DiskfontBase);
  95.             CloseLibrary(cb->cb_DataTypesBase);
  96.         }
  97.         else
  98.             fset(cb->cb_Lib.lib_Flags,LIBF_DELEXP);
  99.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  100.     if(ftst(cb->cb_Lib.lib_Flags,LIBF_DELEXP))        /* Delayed expunge set? */
  101.         Seg=LibExpunge(cb);
  102.     return(Seg);
  103. }    /* LibClose */
  104.  
  105. ASM BPTR LibExpunge(R_A6 struct ClassBase *cb)
  106. {
  107.     BPTR Seg=0;
  108.  
  109.     if(cb->cb_Class==NULL)                                                /* No accesors? */
  110.     {
  111.         Seg=cb->cb_SegList;
  112.         Remove((struct Node *)cb);                                    /* Remove from library list */
  113.         CloseLibrary(cb->cb_UtilityBase);
  114.         CloseLibrary(cb->cb_DOSBase);
  115.         CloseLibrary(cb->cb_GfxBase);
  116.         CloseLibrary(cb->cb_IntuitionBase);
  117.         FreeMem((APTR)((ULONG)(cb)-(ULONG)(cb->cb_Lib.lib_NegSize)),
  118.                         cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  119.     }
  120.     return(Seg);
  121. }    /* LibExpunge */
  122.